import defaultSettings from '@/config/settings.json'
import { Directive } from 'vue'
import { useAppStore } from '@/store'
export const permission: Directive = {
  mounted(el, binding) {
    if (!defaultSettings.pageBtnFormServer) return
    const appStore = useAppStore()
    const { value } = binding
    /**根据_去切割获取到按钮标识返回新数组 */

    const res = (appStore.getCurrentPageButton as any).map(item => item.code.split('_')[1])
    /**判断当前按钮是否有权限显示 */
    const hasIntersection = res.some(item => value.includes(item))
    // console.log(
    //   '🚀 ~ mounted ~ getCurrentPageButton:',
    //   appStore.getCurrentPageButton,
    //   hasIntersection,
    //   value
    // );
    if (!hasIntersection) {
      //
      /**
       * 两种方案
       * 删除dom会触发重绘
       * display能直接html里修改显示出来dom
       */
      el.remove()
      // el.style.display = 'none';
    }
  },
}
